// custom-tab-bar/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  
  /**
   * 组件的初始数据
   */
  data: {
    show:true,
    bool:true,
    active: 0,
    "list": [
      {
          "text": "首页",
          "pagePath": "/pages/index/index",
          "icon":"wap-home-o"
      },
      {
        "text": "专题",
        "pagePath": "/pages/topic/topic",
        "icon":"label-o"
  },
      {
          "text": "分类",
          "pagePath": "/pages/classify/classify",
          "icon":"qr"
      },
     
      {
          "text": "购物车",
          "pagePath": "/pages/cart/cart",
          "icon":"shopping-cart-o"
      },
      {
          "text": "我的",
          "pagePath": "/pages/user/user",
          "icon":"user-o"
      }
  ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.setData({ active: event.detail });
      // console.log(event); let token =  wx.getStorageSync('token');
      let token = wx.getStorageSync('token');
      let path = this.data.list[event.detail].pagePath;
      console.log(token);
      if (path == '/pages/cart/cart' && !token) {
        this.getTabBar().setData({
          active:4
        })
       
        wx.switchTab({
          url: "/pages/user/user"
        })
        wx.showToast({
          title: '请先登录',
          icon:'none'
        })
        return 
      }
      wx.switchTab({
        url: path,
      })
    },
  }
})
